<?php

namespace app\admin\logic\notice;

use app\common\model\order\ShipOrder;
use app\common\model\order\Order;
use app\common\model\changeticket\ChangeTicket;
use app\common\model\ordercomment\Ordercomment;
use app\common\model\hotel\Hotel;

class NoticeLogic
{
    public static function getNums()
    {
        $num570 = ShipOrder::whereIn('status', [ShipOrder::IS_PAID, ShipOrder::UN_REFUND_TICKET, ShipOrder::UN_REFUND_MONEY, ShipOrder::TC_REFUND_FAIL, ShipOrder::TICKET_FAIL])->count();
        $num585 = Order::whereIn('status', [Order::IS_PAID, Order::REFUND_APPLY])->count();
        $num494 = ChangeTicket::where('status', ChangeTicket::UN_PASS)->count();
        $num595 = Ordercomment::where('status', Ordercomment::UN_PASS)->count();
        $num600 = Hotel::where(['status' => Hotel::UN_CHECKED, 'sale_status' => Hotel::SALE_STATUS_UP])->count();
        $numOutTime = 0;
        //过期提醒
        $timeOuts = Order::where('status', Order::IS_PAID)->field('id,go_date')->select()->toArray();
        if ($timeOuts) {
            $outTime = time() + 86400;
            foreach ($timeOuts as $item) {
                $time = strtotime($item['go_date']);
                if ($time < $outTime) {
                    $numOutTime++;
                }
            }
        }
        $data = [
            ['rule_id' => 570, 'num' => $num570, 'total' => $num570],                           //船票订单列表
            ['rule_id' => 585, 'num' => $num585 + $numOutTime, 'total' => $num585 + $num494 + $numOutTime],   //商品订单列表
            ['rule_id' => 594, 'num' => $num494, 'total' => $num585 + $num494],                 //商品改签列表
            ['rule_id' => 595, 'num' => $num595, 'total' => $num585 + $num494 + $num595],       //商品改签列表
            ['rule_id' => 600, 'num' => $num600, 'total' => $num600]                            //酒店列表
        ];
        return ['nums' => $data];
    }
}
